#include<stdio.h>
const int maxn=5010;
int main()
{
	int n,x[maxn],y[maxn],p[maxn];
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d%d",&x[i],&y[i]);
	}
	int ans,num1,num2,sum=0,max=y[0]-x[0],m;
	for(int i=1;i<n;i++){
		p[i]=y[i]-x[i];
		if(max<p[i]){
			max=p[i];
			m=i;
		}
		sum++;
		if(y[m]>=n&&x[m]>=1){
			printf("%d",sum);
			return 0;
		}
	}
	max=0;
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			num1=x[j]-x[m];
			num2=y[j]-y[m];
			if(x[j]-x[m]<0)
				num1=0;
			if(y[j]-y[m]<0)
				num2=0;
			ans=num1+num2;
			if(ans>max){
				max=ans;
				if(x[j]-x[m]<0)
					y[m]=y[j];
				else if(y[j]-y[m]<0)
					x[m]=x[j];
				else{
					x[m]=x[j];
					y[m]=y[j];
				} 
			}
		}
		sum++;
		if(y[m]>=n&&x[m]>=1){
			printf("%d",sum);
			return 0;
		}
	}
} 
